package my.syncfilter;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtils
{
    private static Logger logger = LoggerFactory.getLogger(CommonUtils.class);
    private static final String CONDITION_FIELD_PATTEN_REG = "(?<=\\()[^\\)]+";

    public static String getProperties(Properties properties, String key)
    {
        return getProperties(properties,key,null);
    }

    public static String getProperties(Properties properties,String key,String defalut)
    {
        if(properties.containsKey(key))
        {
            return String.valueOf(properties.get(key));
        }
        return defalut;
    }


    public static String getExpField(String str)
    {
        if (StringUtils.isEmpty(str))
        {
            return str;
        }
        Pattern pattern = Pattern.compile(CONDITION_FIELD_PATTEN_REG);
        Matcher m = pattern.matcher(str.toUpperCase());
        while (m.find())
        {
            return m.group();
        }
        return str;
    }
}
